@use "variables";

html {
  --bt-table-border-color: #{variables.$border-color};
  --bt-table-loading-bg: #{variables.$background};
  --bt-table-loading-color: #{variables.$color};
}

html[data-bs-theme="dark"] {
  --bt-table-border-color: #{variables.$dark-border-color};
  --bt-table-loading-bg: #{variables.$color};
  --bt-table-loading-color: #{variables.$background};
}

.bootstrap-table {
  .fixed-table-toolbar {
    &::after {
      content: "";
      display: block;
      clear: both;
    }

    .bs-bars,
    .search,
    .columns {
      position: relative;
      margin-top: 10px;
      margin-bottom: 10px;
    }

    .columns {
      .btn-group > .btn-group {
        display: inline-block;
        margin-left: -1px !important;

        > .btn {
          border-radius: 0;
        }

        &:first-child > .btn {
          border-top-left-radius: 4px;
          border-bottom-left-radius: 4px;
        }

        &:last-child > .btn {
          border-top-right-radius: 4px;
          border-bottom-right-radius: 4px;
        }
      }

      .dropdown-menu {
        text-align: left;
        max-height: 300px;
        overflow: auto;
        -ms-overflow-style: scrollbar;
        z-index: 1001;
      }

      label {
        display: block;
        padding: 3px 20px;
        clear: both;
        font-weight: normal;
        line-height: 1.4286;
      }
    }

    .columns-left {
      margin-right: 5px;
    }

    .columns-right {
      margin-left: 5px;
    }

    .pull-right .dropdown-menu {
      right: 0;
      left: auto;
    }
  }

  .fixed-table-container {
    position: relative;
    clear: both;

    .table {
      width: 100%;
      margin-bottom: 0 !important;

      th,
      td {
        vertical-align: middle;
        box-sizing: border-box;
      }

      thead th,
      tfoot th {
        vertical-align: bottom;
        padding: 0;
        margin: 0;

        &:focus {
          outline: 0 solid transparent;
        }

        &.detail {
          width: 30px;
        }

        .th-inner {
          padding: 0.75rem;
          vertical-align: bottom;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .sortable {
          cursor: pointer;
          background-position: right;
          background-repeat: no-repeat;
          padding-right: 30px !important;

          &.sortable-center {
            padding-left: 20px !important;
            padding-right: 20px !important;
          }
        }

        .both {
          background-image: url(variables.$sort-background-image-url-both);
          background-size: 16px 16px;
          background-position: center right 2px;
        }

        .asc {
          background-image: url(variables.$sort-background-image-url-asc);
        }

        .desc {
          background-image: url(variables.$sort-background-image-url-desc);
        }
      }

      tbody tr {
        &.selected td {
          background-color: variables.$hover-bg;
        }

        &.no-records-found td {
          text-align: center;
        }

        .card-view {
          display: flex;

          .card-view-title {
            font-weight: bold;
            display: inline-block;
            min-width: 30%;
            width: auto !important;
            text-align: left !important;
          }

          .card-view-value {
            width: 100% !important;
            text-align: left !important;
          }
        }
      }

      .bs-checkbox {
        text-align: center;

        label {
          margin-bottom: 0;

          input[type="radio"],
          input[type="checkbox"] {
            margin: 0 auto !important;
          }
        }
      }

      &.table-sm .th-inner {
        padding: 0.25rem;
      }
    }

    &.fixed-height {
      &:not(.has-footer) {
        border-bottom: 1px solid var(--bt-table-border-color);
      }

      &.has-card-view {
        border-top: 1px solid var(--bt-table-border-color);
        border-bottom: 1px solid var(--bt-table-border-color);
      }

      .fixed-table-border {
        border-left: 1px solid var(--bt-table-border-color);
        border-right: 1px solid var(--bt-table-border-color);
      }

      .table {
        thead th {
          border-bottom: 1px solid var(--bt-table-border-color);
        }
      }

      .table-dark {
        thead th {
          border-bottom: 1px solid variables.$dark-border-color;
        }
      }
    }

    .fixed-table-header {
      overflow: hidden;
    }

    .fixed-table-body {
      overflow: auto;
      height: 100%;

      .fixed-table-loading {
        align-items: center;
        background: var(--bt-table-loading-bg);
        display: flex;
        justify-content: center;
        position: absolute;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        z-index: 1000;
        transition: visibility 0s, opacity 0.15s ease-in-out;
        opacity: 0;
        visibility: hidden;

        &.open {
          visibility: visible;
          opacity: 1;
        }

        .loading-wrap {
          align-items: baseline;
          display: flex;
          justify-content: center;

          .loading-text {
            margin-right: 6px;
          }

          .animation-wrap {
            align-items: center;
            display: flex;
            justify-content: center;
          }

          .animation-dot,
          .animation-wrap::after,
          .animation-wrap::before {
            content: "";
            animation-duration: 1.5s;
            animation-iteration-count: infinite;
            animation-name: loading;
            background: var(--bt-table-loading-color);
            border-radius: 50%;
            display: block;
            height: 5px;
            margin: 0 4px;
            opacity: 0;
            width: 5px;
          }

          .animation-dot {
            animation-delay: 0.3s;
          }

          .animation-wrap::after {
            animation-delay: 0.6s;
          }
        }

        &.table-dark {
          background: var(--bt-table-loading-color);

          .animation-dot,
          .animation-wrap::after,
          .animation-wrap::before {
            background: var(--bt-table-loading-bg);
          }
        }
      }
    }

    .fixed-table-footer {
      overflow: hidden;
    }
  }

  .fixed-table-pagination {
    &::after {
      content: "";
      display: block;
      clear: both;
    }

    > .pagination-detail,
    > .pagination {
      margin-top: 10px;
      margin-bottom: 10px;
    }

    > .pagination-detail {
      .pagination-info {
        line-height: 34px;
        margin-right: 5px;
      }

      .page-list {
        display: inline-block;

        .btn-group {
          position: relative;
          display: inline-block;
          vertical-align: middle;

          .dropdown-menu {
            margin-bottom: 0;
          }
        }
      }
    }

    > .pagination {
      ul.pagination {
        margin: 0;

        li.page-intermediate {
          a {
            color: #c8c8c8;

            &::before {
              content: "\2B05";
            }

            &::after {
              content: "\27A1";
            }
          }
        }

        li.disabled a {
          pointer-events: none;
          cursor: default;
        }
      }
    }
  }

  &.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1050;
    width: 100% !important;
    background: #fff;
    height: calc(100vh);
    overflow-y: scroll;
  }

  &.bootstrap4,
  &.bootstrap5 {
    .pagination-lg .page-link {
      padding: 0.5rem 1rem;
    }
  }

  &.bootstrap5 {
    .float-left {
      float: left;
    }

    .float-right {
      float: right;
    }
  }
}

/* calculate scrollbar width */
div.fixed-table-scroll-inner {
  width: 100%;
  height: 200px;
}

div.fixed-table-scroll-outer {
  top: 0;
  left: 0;
  visibility: hidden;
  width: 200px;
  height: 150px;
  overflow: hidden;
}

@keyframes loading {
  0% { opacity: 0; }
  50% { opacity: 1; }
  100% { opacity: 0; }
}
